#include <stdio.h>
#include <stdlib.h>
struct clist
{
  int num;
  struct clist *next;
};
typedef struct clist node;
typedef node *clink;
void Printlist(clink head)
{
  clink ptr;
  if (head == NULL)
  {
    printf("\n");
  }
  else
  {
    ptr = head;
    do
    {
      ptr = ptr->next;
      printf("[%d]", ptr->num);
    } while (ptr != head);
    printf("\n");
  }
}
clink Insertnode(clink head, clink ptr, int x)
{
  clink newnode;
  newnode = (clink)malloc(sizeof(node));
  if (!newnode)
  {
    return NULL;
  }
  newnode->num = x;
  newnode->next = NULL;
  if (head == NULL)
  {
    head = newnode;
    newnode->next = head;
  }
  else
  {
    if (ptr == NULL)
    {
      newnode->next = head->next;
      head->next = newnode;
    }
    else
    {
      newnode->next = head->next->next;
      head->next->next = newnode;
    }
  }
  return head;
}
clink Findnode(clink head, int x)
{
  clink ptr, ptr1;
  ptr1 = NULL;
  if (head == NULL)
  {
    return NULL;
  }
  else
  {
    ptr = head;
    do
    {
      if (ptr->num == x)
      {
        ptr1 = ptr;
        break;
      }
      ptr = ptr->next;
    } while (ptr != head);
    return ptr1;
  }
}
clink Deletnode(clink head, clink ptr)
{
  clink ptr1;
  ptr1 = head;
  if (head->next == head)
  {
    head = NULL;
  }
  else
  {
    while (ptr1->next != ptr)
    {
      ptr1 = ptr1->next;
    }
    ptr1->next = ptr1->next->next;
    if (ptr == head)
    {
      head = ptr1;
    }
  }
  return head;
}
void Freelist(clink head)
{
  clink ptr, ptr1;
  ptr1 = head;
  do
  {
    ptr = head->next;
    head = head->next->next;
    free(ptr);
  } while (ptr != ptr1);
}
void main()
{
  int arry[6] = {9, 7, 3, 4, 5, 6};
  int i, num;
  clink head, ptr;
  head = NULL;
  head = Insertnode(head, head, arry[0]);
  if (!head)
  {
    exit(1);
  }
  Printlist(head);
  head = Insertnode(head, NULL, arry[1]);
  Printlist(head);
  for (i = 2; i < 6; i++)
  {
    head = Insertnode(head, head, arry[i]);
    Printlist(head);
  }
  while (1)
  {
    scanf("%d", &num);
    if (num < 0)
    {
      exit(1);
    }
    else
    {
      ptr = Findnode(head, num);
      if (ptr == NULL)
      {
        printf("1\n");
        continue;
      }
      head = Deletnode(head, ptr);
      printf("1");
      Printlist(head);
    }
  }
  Freelist(head);
}